<!-- 首页 -->
<template>
	<view class="container">
		<TopNav title="商家入驻协议" bg-color="#fff"></TopNav>
		<view class="content p-12">
			<text v-html="appConfig.technician_tcp"></text>
		</view>
		
		<view class="fixed-bottom p-lr16">
			<view class="flex align-items-baseline tips">
				<u-checkbox-group v-model="checked">
					<u-checkbox activeColor="#FE3F59" :name="true" size="32rpx"></u-checkbox>
				</u-checkbox-group>
				<view class="f-s12">
					我已阅读并同意<text class="text-theme">《商家入驻协议》</text>
				</view>
			</view>
			<view class="self-btn full-width m-t6" hover-class="pressed" @click="handleSubmit">
				<text>申请入驻</text>
			</view>
		</view>
		<Toast></Toast>
	</view>
</template>

<script>
	import {
		signAgreement
	} from "@/api/mine"
	import {appConfig} from "@/api/document"
	export default {
		name: "",
		data() {
			return {
				checked: [false],
				appConfig:  {}
			}
		},
		onLoad() {
			this.getAppConfig()
		},
		methods: {
			getAppConfig(){
				// 获取应用配置
				appConfig().then(res=>{
					this.appConfig = res.data || {}
				}).catch(()=>{
					this.appConfig =  {}
				})
			},
			handleSubmit() {
				if (this.checked[0]) {
					
					// authDetails().then(res => {
					// 	let {
					// 		data: {
					// 			tcp = {}
					// 		} = {}
					// 	} = res || {} // 最外层也设置默认值
					// 	let tcpStatus = tcp?.status
					// 	// 检查签署协议情况
					// 	if (tcpStatus === 1) {
					// 	// 已签署，
					
					// 	} else {
					// 		// 未签署，跳转签署服务协议页
					// 		this.$modal.closeLoading()
					// 		this.$tab.redirectTo('merchant-agreement')
					// 	}
					// }).catch(() => this.$modal.closeLoading())
					
					// this.$tab.navigateTo('./steps/index')
					this.$modal.loading('协议上传中').then(() => {
						signAgreement({
							sign: '同意'
						}).then(() => {
							this.$store.dispatch('GetInfo').then(res => {
								this.$modal.closeLoading()
								let userInfo = this.$store.state.user.userInfo
								if (!userInfo.technician_tcp || userInfo.technician_data
									.status !== 1) {
									// 基本资料是否认证
									this.$tab.redirectTo('./steps/index')
								} else {
									this.$tab.reLaunch('/pages/index/index')
								}
							})
						}).catch(() => this.$modal.closeLoading())
					})

				} else {
					this.$toast('请阅读并同意《商家入驻协议》后申请入驻'); // 3 秒后消失
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	@import '@/common/css/var.scss';

	page {
		@include fixed-bottom(50rpx);
		background-color: #fff
	}

	.container {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;


		.content {
			width: 100%;
		}

		.tips {
			width: 100%;
			padding: 20rpx 24rpx;
			background: #FEEBEE;
			width: 100%;
			position: absolute;
			bottom: 100%;
			left: 0;
		}

	}
</style>